Peter Penzov
Peter Penzov

Reputation: 1754

Set property value into JSF code

I'm interested how I can set value into JSF page. For example something like this.

itemValue="#{ud.datacenterId = datacenters.datacenterid}"

How I can directly assign the value of datacenters.datacenterid into ud.datacenterId? Is this possible?

Upvotes: 0

Views: 1264

Answers (1)

BalusC
BalusC

Reputation: 1109874

You can only do that with an action(listener) method.

E.g.

<h:commandButton ... action="#{ud.setDatacenterId(datacenters.datacenterid)}" />

or

<h:commandButton ... actionListener="#{ud.setDatacenterId(datacenters.datacenterid)}" />

or

<h:commandButton ...>
    <f:setPropertyActionListener target="#{ud.datacenterId}" value="#{datacenters.datacenterid}" />
</h:commandButton>

or

<h:commandButton ...>
    <f:ajax listener="#{ud.setDatacenterId(datacenters.datacenterid)}" />
</h:commandButton>

etc.

If your follow-up question is actually "How to invoke it during page load?", then you actually have a different question. Based on your question history, you're using PrimeFaces. Look at <p:remoteCommand autoRun="true"> then. I would still only wonder if this all is really the right solution to the concrete functional requirement which you've had in mind.

Upvotes: 1

Related Questions