curious
curious

Reputation: 933

Updating command link value in JSF 2.0

I have a command link and on its click i have a dialog in JSF 2.0 as:

<p:commandLink  value="(.3%)" style="font-size:10px;" onclick="lrDlg.show()"     id="percentchange"/>

Now on the dialog i want the value of command link value as:

<h:outputText value="Change Value" />
<h:panelGroup>
<p:inputText size="10" value="#{bean.changeValue}" required="false"
styleClass=" ui-inputfield ui-widget ui-state-default ui-corner-all " />
<h:outputText value="" style="font-size:10px;" />
</h:panelGroup>

My Question is how i update the value in inputtext so as to reflect in commandlink value(shown as "(.3%)".

Upvotes: 3

Views: 1894

Answers (2)

Bhesh Gurung
Bhesh Gurung

Reputation: 51030

Use JQuery to update the input-field value before you show the dialog:

Give an id to the input-field:

<h:inputText id="inputFldId" value="Change Value" />

Javascript function:

function updateFldAndShowDlg() {
    var btnVal = jQuery("#percentchange").text();
    jQuery("#inputFldId").val(btnVal);
    lrDlg.show();
}

Use above function on the command-link onclick event:

<p:commandLink  value="(.3%)" style="font-size:10px;" onclick="updateFldAndShowDlg()"     id="percentchange"/>

Upvotes: 0

BalusC
BalusC

Reputation: 1109874

Make it a bean property.

private String commandLinkValue;

public Bean() {
    commandLinkValue = "(.3%)";
}

// ...

with

<p:commandLink value="#{bean.commandLinkValue}" ...>

and

<h:inputText value="#{bean.commandLinkValue}" ...>

Upvotes: 2

Related Questions