You need to sign in to do that
Don't have an account?

Problem in apex:input in apex:pageBlockTable when using a Map
Hi all,
I'm using pageBlockTable to display rows of an inner class in my controller. Now, I also want every row to have an option to be deleted. I found solutions online similar to http://sfdcsrini.blogspot.com/2014/12/adding-and-deleting-rows-dynamically-in.html . But I would like to avoid using apex:variable because I think it's not that straightforward. So I tried to use a Map instead of a List of Row objects where the keys are the rowId of the Row objects.
Here's my controller code:
And here's my visualforce code:
Unfortunately, when I try to save the VisualForce page, I get the error:
I figured that this is the line that caused the error:
I know that I can go back to the solution I found online regarding deleting rows, but I just don't get it why I'm getting this error. When I was using Lists before, the line
Thanks,
Mishael
I'm using pageBlockTable to display rows of an inner class in my controller. Now, I also want every row to have an option to be deleted. I found solutions online similar to http://sfdcsrini.blogspot.com/2014/12/adding-and-deleting-rows-dynamically-in.html . But I would like to avoid using apex:variable because I think it's not that straightforward. So I tried to use a Map instead of a List of Row objects where the keys are the rowId of the Row objects.
Here's my controller code:
public class TestInputController { public Map<Integer, Row> rows { get; set; } public TestInputController() { rows = new Map<Integer, Row>(); } public void addRow() { Integer rowId = rows.size(); rows.put(rowId , new Row(rowId)); } public void removeRow() { rows.remove(Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIdToRemove'))); } public class Row { public Integer rowId { get; set; } public Row(Integer rowId) { this.rowId = rowId; } } }
And here's my visualforce code:
<apex:page controller="TestInputController" docType="html-5.0"> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:pageBlockTable value="{!rows}" var="rid" id="tablet"> <apex:column headerValue="ID"> <apex:input type="number" value="{!rows[rid].rowId}" /> </apex:column> <apex:column headerValue="Action"> <apex:commandButton action="{!removeRow}" value="x" rerender="tablet"> <apex:param value="{!rows[rid].rowId}" name="rowIdToRemove" /> </apex:commandButton> </apex:column> </apex:pageBlockTable> <apex:pageBlockSectionItem > <apex:commandButton value="Add Row" action="{!addRow}" rerender="tablet"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Unfortunately, when I try to save the VisualForce page, I get the error:
Error: Expected input type 'text', got 'number' for Id data type
I figured that this is the line that caused the error:
<apex:input type="number" value="{!rows[rid].rowId}" />
I know that I can go back to the solution I found online regarding deleting rows, but I just don't get it why I'm getting this error. When I was using Lists before, the line
<apex:input type="number" value="{!row.rowId}" />works (where row is the var name i used in the pageBlockTable). Am I missing something here? Or is this a bug?
Thanks,
Mishael
<apex:input type="auto" value="{!rows[rid].rowId}" />
Mark this as best answer if it solves your problem.
All Answers
<apex:input type="auto" value="{!rows[rid].rowId}" />
Mark this as best answer if it solves your problem.
That worked for me. Thank you very much!
Regards,
Mishael