sâmbătă, 14 februarie 2015

[OmniFaces utilities (2.0)] Get the currently invoked UI command component


[OmniFaces utilities] The getCurrentCommand() method returns the currently invoked UI command component, or null if there is none, which may happen when the current request is not a postback request at all, or when the view has been changed by for example a successful navigation. If the latter is the case, you'd better invoke this method before navigation.

Method:

OmniFaces 2.4OmniFaces 2.0
Usage:

JSF Page
<h:form id="myFormId">
 <o:outputLabel id="nameLabelId" for="nameId" value="Name"/>
 <h:inputText id="nameId" value="#{playerBean.name}"/>        
 <!-- The UICommand expected to be returned by the Components.getCurrentCommand() -->
 <h:commandButton id="btnId" value="Save" action="#{playerBean.someAction()}"/> 
</h:form>   

After the above form is submitted
import org.omnifaces.util.Components;
...
UICommand command = Components.getCurrentCommand();
System.out.println("Command clientId: " + command.getClientId());

Output:
Command clientId: myFormId:btnId

Niciun comentariu:

Trimiteți un comentariu