sai kiran
sai kiran

Reputation: 1

How to enable and disable command link in jsf?

I am very new to jsf .I have created an arraylist in java class which contains 4 columns and 20 rows.There is a column which have further data linked to it when we click on that specific entry.I want to enable command link for those entries only and the rest of the data should be just displayed as it is as(command link should be disabled).I have tried them in different ways but I was getting both the output label and the command link at the same time(it means I am getting the data twice).But I need to show the data only once.Some one please suggest me a way to solve this.Below is my code where sampleMB is my managed bean and there is a column1 which has 20 rows where 4 rows have to be enabled with a command link on a condition that the data in those rows contains string "XYZ" and the rest 16 rows should be displayed as it is.

Any help will be really appreciated.

<p:dataTable id="table" value="#{sampleMB.List1}" var="cList" scrollable="true" scrollHeight="400">
    <p:column headerText="column1"  >
    <h:outputLabel value="#{cList.column1 }" >
        <p:commandLink  value="#{cList.column1}"  ajax="false" style="text-decoration:underline" rendered="#{cList.card_slot.contains('XYZ')}" /> </h:outputLabel>
    </p:column> 
</p:dataTable>

Upvotes: 0

Views: 4207

Answers (1)

peterremec
peterremec

Reputation: 516

What about something like this:

<p:dataTable id="table" value="#{sampleMB.List1}" var="cList" scrollable="true" scrollHeight="400">
    <p:column headerText="column1">
        <h:outputLabel value="#{cList.column1 }" rendered="#{not cList.card_slot.contains('XYZ')}" />
        <p:commandLink  value="#{cList.column1}"  ajax="false" style="text-decoration:underline" rendered="#{cList.card_slot.contains('XYZ')}" />
    </p:column> 
</p:dataTable>

If you just want to enable/disable command link, you should use disabled attribute instead of rendered and remove h:outputLabel.

Upvotes: 1

Related Questions