Skip to content

Commit

Permalink
Merge #5153, #5160 and #5182 from 4.0 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Dec 13, 2022
2 parents aecbc3c + 6841827 commit 84d606f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import jakarta.faces.component.html.HtmlCommandLink;
import jakarta.faces.component.html.HtmlCommandScript;
import jakarta.faces.component.html.HtmlDataTable;
import jakarta.faces.component.html.HtmlDoctype;
import jakarta.faces.component.html.HtmlForm;
import jakarta.faces.component.html.HtmlGraphicImage;
import jakarta.faces.component.html.HtmlInputFile;
Expand Down Expand Up @@ -89,7 +90,7 @@ public HtmlLibrary(String namespace) {

addHtmlComponent("html", UIOutput.COMPONENT_TYPE, "jakarta.faces.Html");

addHtmlComponent("doctype", UIOutput.COMPONENT_TYPE, "jakarta.faces.Doctype");
addHtmlComponent("doctype", HtmlDoctype.COMPONENT_TYPE, "jakarta.faces.Doctype");

addHtmlComponent("inputFile", HtmlInputFile.COMPONENT_TYPE, "jakarta.faces.File");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ protected String getCurrentValue(FacesContext context, UIComponent component) {

String currentValue = null;
Object currentObj = getValue(component);
if (currentObj != null) {
currentValue = getFormattedValue(context, component, currentObj);
}
currentValue = getFormattedValue(context, component, currentObj);
return currentValue;

}
Expand Down
30 changes: 30 additions & 0 deletions impl/src/main/java/com/sun/faces/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static com.sun.faces.util.MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID;
import static com.sun.faces.util.MessageUtils.NULL_VIEW_ID_ERROR_MESSAGE_ID;
import static com.sun.faces.util.MessageUtils.getExceptionMessageString;
import static java.lang.Character.isDigit;
import static java.util.Collections.emptyList;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.SEVERE;
Expand Down Expand Up @@ -1559,4 +1560,33 @@ public static String ensureLeadingSlash(String s) {
}
}

/**
* Extract first numeric segment from given client ID.
* <ul>
* <li>'table:1:button' should return 1</li>
* <li>'table:2' should return 2</li>
* <li>'3:button' should return 3</li>
* <li>'4' should return 4</li>
* </ul>
* @param clientId the client ID
* @param separatorChar the separator character
* @return first numeric segment from given client ID.
* @throws NumberFormatException when given client ID doesn't have any numeric segment at all.
*/
public static int extractFirstNumericSegment(String clientId, char separatorChar) {
int nextSeparatorChar = clientId.indexOf(separatorChar);

while (clientId.length() > 0 && !isDigit(clientId.charAt(0)) && nextSeparatorChar >= 0) {
clientId = clientId.substring(nextSeparatorChar + 1);
nextSeparatorChar = clientId.indexOf(separatorChar);
}

if (clientId.length() > 0 && isDigit(clientId.charAt(0))) {
String firstNumericSegment = nextSeparatorChar >= 0 ? clientId.substring(0, nextSeparatorChar) : clientId;
return Integer.parseInt(firstNumericSegment);
}

throw new NumberFormatException("there is no numeric segment");
}

}
31 changes: 12 additions & 19 deletions impl/src/main/java/jakarta/faces/component/UIData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package jakarta.faces.component;

import static com.sun.faces.util.Util.extractFirstNumericSegment;
import static com.sun.faces.util.Util.isNestedInIterator;

import java.io.IOException;
Expand Down Expand Up @@ -937,27 +938,19 @@ public boolean invokeOnComponent(FacesContext context, String clientId, ContextC
// clientId will be something like form:outerData:3:outerColumn
// for a non-nested table. clientId will be something like
// outerData:3:data:3:input for a nested table.
// We need to find the first occurring client ID segment which is parseable as a number.
if (clientId.startsWith(myId)) {
try {
int preRowIndexSep, postRowIndexSep;

if (-1 != (preRowIndexSep = clientId.indexOf(sepChar, myId.length()))) {
// Check the length
if (++preRowIndexSep < clientId.length()) {
if (-1 != (postRowIndexSep = clientId.indexOf(sepChar, preRowIndexSep + 1))) {
try {
newRow = Integer.parseInt(clientId.substring(preRowIndexSep, postRowIndexSep));
} catch (NumberFormatException ex) {
// PENDING(edburns): I18N
String message = "Trying to extract rowIndex from clientId \'" + clientId + "\' " + ex.getMessage();
throw new NumberFormatException(message);
}
setRowIndex(newRow);
if (isRowAvailable()) {
found = super.invokeOnComponent(context, clientId, callback);
}
}
}
try {
newRow = extractFirstNumericSegment(clientId.substring(myId.length()), sepChar);
} catch (NumberFormatException ex) {
// PENDING(edburns): I18N
String message = "Trying to extract rowIndex from clientId \'" + clientId + "\' " + ex.getMessage();
throw new NumberFormatException(message);
}
setRowIndex(newRow);
if (isRowAvailable()) {
found = super.invokeOnComponent(context, clientId, callback);
}
} catch (FacesException fe) {
throw fe;
Expand Down
26 changes: 26 additions & 0 deletions impl/src/test/java/com/sun/faces/util/TestUtil_local.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,30 @@ public void testSplit() {
assertEquals(result[1], "Zm9vQmFyVmFsdWUy");
}

public void testExtractFirstNumericSegment() {
char separatorChar = ':';

assertEquals(1, Util.extractFirstNumericSegment("form:table:1:button", separatorChar));
assertEquals(2, Util.extractFirstNumericSegment("form:table:nested:2:button", separatorChar));
assertEquals(3, Util.extractFirstNumericSegment("form:table:3", separatorChar));
assertEquals(4, Util.extractFirstNumericSegment("4:button", separatorChar));
assertEquals(5, Util.extractFirstNumericSegment("5", separatorChar));

try {
Util.extractFirstNumericSegment("none", separatorChar);
fail();
}
catch (NumberFormatException e) {
assertEquals("there is no numeric segment", e.getMessage());
}

try {
Util.extractFirstNumericSegment("", separatorChar);
fail();
}
catch (NumberFormatException e) {
assertEquals("there is no numeric segment", e.getMessage());
}
}

} // end of class TestUtil_local

0 comments on commit 84d606f

Please sign in to comment.