- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Variable für for-Schleife in Integer casten?
Hallo zusammen,
ich habe auch schon die Suche bemüht, aber leider nichts passendes zu meiner Frage gefunden.
Ich habe in meinem Datensatz ein Formularfeld vom Typ DOMTABLE und möchte im PDF-Ausgabekanal gezielt auf die einzelnen Inhalte zugreifen.
Dazu nutze ich zwei verschaltete for-Schleifen was auch funktionieren würde, wenn meine Variablen "rows" und "cols" vom Typ Integer wären.
Kann ich diese irgendwie zu Integer casten? Derzeit sind sie vom Typ TemplateDocumentImpl.
$CMS_IF(cs_tabellen.getRows() > 1)$
$CMS_SET(rows)$$CMS_VALUE(cs_tabellen.getRows())$$CMS_END_SET$
$CMS_SET(cols)$$CMS_VALUE(cs_tabellen.getColumns())$$CMS_END_SET$
$CMS_FOR(row, [0 .. rows])$
$CMS_FOR(col, [0 .. cols])$
$CMS_VALUE(cs_tabellen.getCell(row,col).getShortContent(#global.project.userservice))$
$CMS_END_FOR$
$CMS_END_FOR$
$CMS_END_IF$
- Labels:
-
Developers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sie brauchen wahrscheinlich nicht casten, wenn sie die Variablen nach folgendem Schema setzen:
$CMS_SET(variablenname, wert)$
also z.B.
$CMS_SET(rows, cs_tabellen.getRows())$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Vielen Dank, das funktioniert soweit.
Jetzt habe ich aber noch das Problem, dass ich innerhalb von $CMS_VALUE()$ kein weiteres $CMS_VALUE()$ nutzen kann.
Ich kann ja innerhalb der inneren Schleife per #for.index nur auf deren Index zugreifen. Ich versuche mir mit $CMS_SET()$ den index der äußeren Schleife in einer eigenen Variablen zu parken:
$CMS_SET(rows, cs_tabellen.getRows()-1)$
$CMS_SET(cols, cs_tabellen.getColumns()-1)$
$CMS_FOR(row, [0 .. rows])$
$CMS_SET(i, #for.index)$
$CMS_FOR(col, [0 .. cols])$
$CMS_VALUE(cs_tabellen.getCell(i,#for.index).getShortContent(#global.project.userservice))$
$CMS_END_FOR$
$CMS_END_FOR$
getCell(i,...) wird aber nicht ausgewertet, da der Integerwert für i nicht eingesetzt wird.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hallo Herr Wehe,
funktioniert denn
getCell(row,col)
hier nicht? Falls es nicht funktioniert, was gibt denn
$CMS_VALUE(row.getClass())$
$CMS_VALUE(col.getClass())$
aus?
Viele Grüsse aus Dortmund,
Holger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
getCell(row, col) funktioniert leider nicht.
$CMS_VALUE(row.getClass())$ bzw. $CMS_VALUE(col.getClass())$ gibt beide Male
java.math.BigInteger
aus.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hallo,
auf einem Objekt vom Typ BigInteger kannst du die Methode "intValue()" aufrufen um an die Integer Werte zu kommen.
Also:
getCell(row.intValue(), col.intValue())
Viele Grüße
Rouven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Was genau heißt "funktioniert nicht"? In einem Testprojekt habe ich das mal nachgestellt, und keine Probleme gesehen:
$CMS_FOR(r, [0..2])$
$CMS_FOR(c, [0..2])$
$CMS_SET(cell, tbl.getCell(r,c))$
$CMS_VALUE(r + ", " + c + " = " + cell.row + ", " + cell.column)$<br>
$CMS_END_FOR$
$CMS_END_FOR$
Die Ausgabe ist:
0, 0 = 0, 0
0, 1 = 0, 1
0, 2 = 0, 2
1, 0 = 1, 0
1, 1 = 1, 1
1, 2 = 1, 2
2, 0 = 2, 0
2, 1 = 2, 1
2, 2 = 2, 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Vielen Dank für eure zahlreichen Antworten!
Ich habe es jetzt hinbekommen und wie Peter wohl vermutet hat lag es gar nicht am Datentyp von row und col, sondern am generierten XML. Ein CDATA kann Wunder wirken... folgender Codeblock funktioniert jetzt:
$CMS_IF(cs_tabellen.getRows() > 1)$
$CMS_SET(rows, cs_tabellen.getRows()-1)$
$CMS_SET(cols, cs_tabellen.getColumns()-1)$
$CMS_FOR(row, [0 .. rows])$
$CMS_FOR(col, [0 .. cols])$
<![CDATA[$CMS_VALUE(cs_tabellen.getCell(row,col).getShortContent(#global.project.userservice))$]]>
$CMS_END_FOR$
$CMS_END_FOR$
$CMS_END_IF$

